package com.schoolvisitors.service;

import com.alibaba.fastjson2.JSONObject;
import com.schoolvisitors.enums.ReservationStatusEnum;
import com.schoolvisitors.enums.ReservationTypeEnum;
import com.schoolvisitors.enums.RoomTypeEnum;
import com.schoolvisitors.repository.ReservationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

@Service
public class DashboardService {


    private final ReservationRepository reservationRepository;
    @Autowired
    public DashboardService(ReservationRepository reservationRepository) {
        this.reservationRepository = reservationRepository;
    }

    public JSONObject getDashboardStats() {
        LocalDate today = LocalDate.now();

        long todayReservationUserCount = reservationRepository.countDistinctUserByDate(today);
        long reservationMeetingCount = reservationRepository.countDistinctCubicleNumberByDateAndType(today, ReservationTypeEnum.CUBICLE_MEETING.name());
        long reservationLabCount = reservationRepository.countDistinctCubicleNumberByDateAndType(today, ReservationTypeEnum.CUBICLE_LAB.name());

        JSONObject json = new JSONObject();
        json.put("todayReservationUserCount", todayReservationUserCount);
        json.put("reservationMeetingCount", reservationMeetingCount);
        json.put("reservationLabCount", reservationLabCount);

        return json;
    }
}